package com.seu.me.rest;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * Created by liangfeihu on 2017/11/28.
 */
@Slf4j
@RestController
@RequestMapping("/me/seu")
public class HelloRest {

    @RequestMapping(value = "/test/{type}", method = RequestMethod.GET, produces = "application/json;charset:utf-8;")
    public JSONObject mytest(@PathVariable String type, HttpServletRequest request) {
        log.info("RequestURI={}", request.getRequestURI());
        log.error("RequestURL={}", request.getRequestURL());
        log.info("ContextPath={}", request.getContextPath());
        log.error("ServletPath={}", request.getServletPath());
        log.info("RemoteAddr={}", request.getRemoteAddr());
        log.info("ServerPort={}", request.getServerPort());

        JSONObject object = new JSONObject();
        object.put("key1", "恭喜发财");
        object.put("key2", "大吉大利");
        object.put("myType", type);

        log.info("now time : {}", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        return object;
    }
}
